#pragma once

/*
 * pipe config.
 */

#include <string>
#include <vector>
#include "pipe_define.h"

namespace anet {
	namespace pipe {
		// connection mode information.
		struct connectInfo {
			// server id
			uint32 serverId;

			// server address.
			std::string addr;

			// server port
			uint16 port;

			// server token.
			std::string token;
		};

		// listen mode information.
		struct listenInfo {
			// listen address
			std::string addr;

			// listen port
			uint16 port;

			// server token.
			std::string token;
		};

		// pipe config from xml.
		class CPipeConfig final {
		public:
			CPipeConfig();
			virtual ~CPipeConfig();
			CPipeConfig(const CPipeConfig& rhs) = delete;
			CPipeConfig& operator=(const CPipeConfig& rhs) = delete;

		public:
			bool Load(const char* filePath);
			uint32 GetServerId() const;
			const std::vector<listenInfo>& GetListens() const;
			const std::vector<connectInfo>& GetConnects() const;
			
		protected:
			// listen & connection node repeat check.
			bool listenNodeCheck(const listenInfo& listenNode) const;
			bool connectNodeCheck(const connectInfo& connectNode) const;

		private:
			// local pipe id.
			uint32 m_id{ 0 };

			// pipe's listen list
			std::vector<listenInfo> m_listens;

			// pipe's connect list
			std::vector<connectInfo> m_connects;
		};
	}
}